package cn.com.netedge.iot.frontend.comm.nio;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * 初始化服务,注册ChannelInboundHandlerAdapter
 */
public class FeChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        // 向管道注册解码器与handler
        pipeline.addLast(new LoggingHandler(LogLevel.INFO));
        pipeline.addLast(new FeChannelHandler());
        pipeline.addLast(new ByteArrayEncoder());
        pipeline.addLast(new MessageDecoder());
        pipeline.addLast(new MessageDealHandler());
    }
}
